<?
//import ("jsml/excanvas.compiled.js");
/*<@
import ("jsml/php.default.min.js");
@>*/
import ("stock_analyser_ChartView");
import ("stock_price_LivePriceView");
import ("stock_price_PriceVo");
import ("stock_analyser_AnalyserConfig");
class stock_analyser_AnalyserView extends jsml_View{
	public static function main(){
		_($__document)->ready(function(){
			$config = stock_analyser_AnalyserConfig::$config;
			$view = $config->getBean($config->AnalyserView);
			_($__document->body)->append($view->div);
			$view->view();
		});
	}
	
	public function construct($key) {
		parent::construct($key);
		if (null == $key) {
			$this->chartViewMap["stock"] = $this->config->getBean($this->config->ChartView);
			$this->chartViewMap["vn"] = $this->config->getBean($this->config->ChartView);
			$this->chartViewMap["ha"] = $this->config->getBean($this->config->ChartView);
			
			$this->chartViewMap["stock2"] = $this->config->getBean($this->config->ChartView2);
			$this->chartViewMap["vn2"] = $this->config->getBean($this->config->ChartView2);
			$this->chartViewMap["ha2"] = $this->config->getBean($this->config->ChartView2);
			
			$this->chartViewMap["stock3"] = $this->config->getBean($this->config->ChartView3);
			$this->chartViewMap["vn3"] = $this->config->getBean($this->config->ChartView3);
			$this->chartViewMap["ha3"] = $this->config->getBean($this->config->ChartView3);
			
			$this->tableView = $this->config->getBean($this->config->TableView);
			$priceConfig = stock_price_PriceConfig::$config;
			$this->livePriceView = $priceConfig->getBean($priceConfig->LivePriceView);
		}
		return $this;
	}
	
	protected function configCss($key) {
		$css = parent::configCss($key);
		if ($this->config->AnalyserView == $key) {
			$_->extend($css, array(
				"height" => 732,
				"width" => 1300
			));
		}
		return $css;
	}
	
	public $buttonQuickLength = 70;
	public $enablePlus = false;
	public $overviewHrefArray = array();
	public $flagMap = array("__new__"=>1);
	
	public $tableView;
	public $livePriceView;
	public $chartViewMap = array("__new__"=>1);
	public $priceDtArrayMap = array("__new__"=>1);
	public $livePriceDtArrayMap = array("__new__"=>1);
	public function view(){
		?>
<$html>
<div style='<?= $this->getCssString(null) ?> left:0;top:0; width:<?= $this->screenW ?>; height:25'>
<table>
<tr>
<td>
	<button <?= $this->attach('buttonBack') ?>>Back</button>
	<button <?= $this->attach('buttonList') ?>>List</button>
	<button <?= $this->attach('buttonNext') ?>>Next</button>
	|
	<button <?= $this->attach('buttonSave') ?>>Save</button>
	<button <?= $this->attach('buttonDelete') ?>>Delete</button>
	<button <?= $this->attach('buttonClear') ?>>Clear</button>
</td>
<th>stock</th>
<td>
<form>
	<input <?= $this->attach('checkboxAuto') ?> type="checkbox" checked />
	<select <?= $this->attach('selectFilterType') ?> style='width: 100'>
		<option value="minClose">minClose</option>
		<option value="value2">value2</option>
	</select>
	<input <?= $this->attach('textStock') ?> type='text' size='7'></input>
	<select <?= $this->attach('selectStock') ?> style='width: 100'></select>
	<input <?= $this->attach('textRate') ?> type='text' size='7' value=''></input>
	<input <?= $this->attach('textDayBack') ?> type='text' size='7' value='0'></input>
	w<input type='text' name='w34' size='3' value='1' />
	|<input type='text' name='w12' size='3' value='5' />
	ma<input type='text' name='ma1' size='3' value='5' />
	<input type='text' name='ma2' size='3' value='10' />
	<input type='text' name='ma3' size='3' value='60' />
</form>
</td>
<td>
	<button <?= $this->attach('buttonVN') ?>>VN</button>
	<button <?= $this->attach('buttonHA') ?>>HA</button>
	<button <?= $this->attach('buttonStock') ?>>Stock</button>
	<button <?= $this->attach('window.rsi') ?>>RSI</button>
	<button <?= $this->attach('window.table') ?>>Table</button>
	<button <?= $this->attach('window.chart') ?>>Chart</button>
	|<a <?= $this->attach('aOverview') ?> href="" onclick="return false;">overview</a>
</td>
</tr>
</table>
</div>
<div <?= $this->attach('divLivePrice') ?> style="<?= $this->getCssString(null) ?> background-color:gray; left:0; top:25; width:<?= $this->screenW ?>; height:72"></div>
<div <?= $this->attach('divChartView') ?> style="<?= $this->getCssString(null) ?> left:0; top:97; width:<?= $this->screenW ?>; height:<?= $this->screenH - 97 ?>;overflow:auto">
	<div <?= $this->attach('divXPlus') ?> style="<?= $this->getCssString(null) ?> top:100; height:1; background-color:red; visibility:hidden"></div>
	<div <?= $this->attach('divYPlus') ?> style="<?= $this->getCssString(null) ?> left:100; width:1000; background-color:white; border-left:solid 1 red; visibility:hidden"></div>
	<div <?= $this->attach('divDetail') ?> style="<?= $this->getCssString(null) ?> border:solid 1px; width:200; height:200; visibility:hidden">
		<button <?= $this->attach('buttonDetailHide') ?> style="font-weight: bold; width:35; height: 25">Hide</button>
		<button <?= $this->attach('buttonDetailQueryInit') ?> style="font-weight: bold; width:35; height: 25">Init</button>
		<button <?= $this->attach('buttonDetailQueryInitCond') ?> style="font-weight: bold; width:35; height: 25">Cond</button>
		<br/>
		<div <?= $this->attach('divDetailText') ?> style="font-weight: bold"></div>
	</div>
</div>
<div <?= $this->attach('divButtonQuick') ?> style="<?= $this->getCssString(null) ?> border:solid 2px; left:6; top:99; width:<?= $this->screenW - 35 ?>; height:50">
<? for($i=0; $i<$this->buttonQuickLength; $i++){ ?>
<button tag="buttonQuick" style="font-weight: bold; width:35; height: 25">&nbsp;</button>
<? } ?>
</div>

<div <?= $this->attach('divTableView') ?> style="<?= $this->getCssString(null) ?> background-color:black; left:0; top:25; width:<?= $this->screenW ?>; height:<?= $this->screenH - 25 ?>;visibility:hidden;overflow:auto"></div>
<div <?= $this->attach('divLivePriceView') ?> style="<?= $this->getCssString(null) ?> background-color:black; left:0; top:25; width:<?= $this->screenW ?>; height:<?= $this->screenH - 25 ?>;visibility:hidden;overflow:auto"></div>
</$html>
			<?
			$_($html)->appendTo($this->div);
			$divChartView = $this->_("divChartView");
			$this->chartViewMap["vn"]->div->appendTo($divChartView)->css(array(left=>0, top=>0));
			$this->chartViewMap["vn"]->view();
			$this->chartViewMap["ha"]->div->appendTo($divChartView)->css(array(left=>0, top=>1*$this->chartViewMap["stock"]->height));
			$this->chartViewMap["ha"]->view();
			$this->chartViewMap["stock"]->div->appendTo($divChartView)->css(array(left=>0, top=>2*$this->chartViewMap["stock"]->height));
			$this->chartViewMap["stock"]->tableView = $this->tableView;
			$this->chartViewMap["stock"]->view();
			
			$this->chartViewMap["vn2"]->div->appendTo($divChartView)->css(array(left=>0, top=>0));
			$this->chartViewMap["vn2"]->view();
			$this->chartViewMap["ha2"]->div->appendTo($divChartView)->css(array(left=>0, top=>1*$this->chartViewMap["stock"]->height));
			$this->chartViewMap["ha2"]->view();
			$this->chartViewMap["stock2"]->div->appendTo($divChartView)->css(array(left=>0, top=>2*$this->chartViewMap["stock"]->height));
			$this->chartViewMap["stock2"]->tableView = $this->tableView;
			$this->chartViewMap["stock2"]->view();
			
			$this->chartViewMap["vn3"]->div->appendTo($divChartView)->css(array(left=>0, top=>0));
			$this->chartViewMap["vn3"]->view();
			$this->chartViewMap["ha3"]->div->appendTo($divChartView)->css(array(left=>0, top=>1*$this->chartViewMap["stock"]->height));
			$this->chartViewMap["ha3"]->view();
			$this->chartViewMap["stock3"]->div->appendTo($divChartView)->css(array(left=>0, top=>2*$this->chartViewMap["stock"]->height));
			$this->chartViewMap["stock3"]->tableView = $this->tableView;
			$this->chartViewMap["stock3"]->view();
			
			//$this->hideChart = false;
			$this->chartViewMap["stock2"]->div->css("visibility", "visible");
			$this->chartViewMap["vn2"]->div->css("visibility", "visible");
			$this->chartViewMap["ha2"]->div->css("visibility", "visible");
			
			$this->chartViewMap["stock3"]->div->css("visibility", "hidden");
			$this->chartViewMap["vn3"]->div->css("visibility", "hidden");
			$this->chartViewMap["ha3"]->div->css("visibility", "hidden");
			
			$divTableView = $this->_("divTableView");
			$this->tableView->div->appendTo($divTableView);
			_($this->tableView)->bind("rpc.queryMap", function($event, $result){ $this->onRpc("tableView.queryMap", $event, $result); });
			$this->tableView->view();
			$this->tableView->div->bind("click", function($event){ $this->onClick("tableView.div", $event); });
			
			$divLivePriceView = $this->_("divLivePriceView");
			$this->livePriceView->div->appendTo($divLivePriceView);
			//_($this->livePriceView)->bind("rpc.queryMap", function($event, $result){ $this->onRpc("tableView.queryMap", $event, $result); });
			$this->livePriceView->viewLivePrice();
			$this->livePriceView->div->bind("click", function($event){ $this->onClick("livePriceView.div", $event); });
			$this->_("divLivePrice")->bind("click", function($event){ $this->onClick("divLivePrice", $event); });
			
			$divChartView->scrollLeft(9999);
			
			$this->_("divXPlus")->width($this->chartViewMap["stock"]->width);
			$this->_("divYPlus")->height(3*$this->chartViewMap["stock"]->height);
			$this->toFront("divXPlus");
			$this->toFront("divYPlus");
			$this->toFront("divDetail");
			
			$this->_("buttonBack")->bind("click", function($event){ $this->onClick("buttonBack", $event); });
			$this->_("buttonList")->bind("click", function($event){ $this->onClick("buttonList", $event); });
			$this->_("buttonNext")->bind("click", function($event){ $this->onClick("buttonNext", $event); });
			
			$this->_("buttonSave")->bind("click", function($event){ $this->onClick("buttonSave", $event); });
			
			$this->_("checkboxAuto")->bind("click", function($event){ $this->onClick("checkboxAuto", $event); });
			
			$this->_("buttonVN")->bind("click", function($event){ $this->onClick("buttonVN", $event); });
			$this->_("buttonHA")->bind("click", function($event){ $this->onClick("buttonHA", $event); });
			$this->_("buttonStock")->bind("click", function($event){ $this->onClick("buttonStock", $event); });
			$this->_("divButtonQuick")->bind("click", function($event){ $this->onClick("divButtonQuick", $event); });
			$this->_("buttonDetailHide")->bind("click", function($event){ $this->onClick("buttonDetailHide", $event); });
			$this->_("buttonDetailQueryInit")->bind("click", function($event){ $this->onClick("buttonDetailQueryInit", $event); });
			$this->_("buttonDetailQueryInitCond")->bind("click", function($event){ $this->onClick("buttonDetailQueryInitCond", $event); });
			
			$this->_("aOverview")->bind("click", function($event){ $this->onClick("aOverview", $event); });
			
			$this->_("divChartView")->bind("mousemove", function($event){ $this->onMouseMove("divChartView", $event); });
			$this->_("divChartView")->bind("dblclick", function($event){ $this->onDblclick("divChartView", $event); });
			//$this->chartViewMap["stock2"]->div->bind("keypress", function ($event){ $this->onKeypress("stock2", $event); });
			
			_(document)->bind("keypress", function ($event){ $this->onKeypress("document", $event); });

			_($this)->bind("rpc.queryInit", function($event, $result){ $this->onRpc("queryInit", $event, $result); });
			_($this)->bind("rpc.queryPriceDtArrayMap", function($event, $result){ $this->onRpc("queryPriceDtArrayMap", $event, $result); });
			/*
			$this->queryInit();
			setInterval(function(){
				$this->queryInit();
			},30000);
			*/
			setInterval(function(){
				$this->_("buttonList")->click();	
			},15000);
			
			return $this;
	}
	
	public function getStockColor($dt){
		if($dt==null) return "black";
		if($dt["rate"] < -500000) return "blue";
		if($dt["rate"] < -10000) return "blue";
		if($dt["rate"] < -7000) return "black";
		if($dt["rate"] < -5000) return "blue";
		if($dt["rate"] < -3000) return "blue";
		return 'black';
	}
	
	public function onRpc($key, $event, $result){
		if("tableView.queryMap" == $key){
			$dtMap = $result["return"];
			$arrayStock_symbol = array();
			foreach ($dtMap as $symbol=>$value){
				if($symbol=="TOTAL") continue;
				array_push($arrayStock_symbol, $symbol);
			}
			
			$selectStock = $this->_("selectStock");
			$selectedSymbol = $selectStock->prop("value");
			//$arrayStock_symbol = $result["return"]["arrayStock_symbol"];
			?>
<$html>
	<option></option>
<? 
			$selectedIndex = 0;
			foreach($arrayStock_symbol as $i=>$value){ 
				if($value == $selectedSymbol) $selectedIndex = 1*$i + 1;
?>
	<option value="<?= $value ?>"><?= $value ?></option>
			<? } ?>	
</$html>
			<?
			$selectStock->html($html);
			//alert($selectedIndex);
			$selectStock->prop("selectedIndex", $selectedIndex);
			
			$this->_("divButtonQuick")->children()->each( function($i, $element){
				$symbol = $arrayStock_symbol[$this->buttonQuickLength - 1 - $i];
				if($symbol!=null) _($element)->html($symbol);
				else _($element)->html("&nbsp");
				_($element)->css("color", $this->getStockColor($dtMap[$symbol]));
				if($symbol == $this->symbol) _($element)->css("color", "red");
			});
			if($this->flagMap["buttonQuickFirstClicked"]!=1){
				$this->_("divButtonQuick")->children()->last()->click();
				$this->flagMap["buttonQuickFirstClicked"] = 1;
			}
		} else if("queryPriceDtArrayMap" == $key){
			$stock_symbol = $result["paramArray"][0];
			foreach($result["return"]["price"] as $key=>$value){
				$this->priceDtArrayMap[$key] = $value;
			}
			foreach ($result["return"]["newPrice"] as $key=>$value){
				if($value[0]==null) continue;
				$value[0]["__newPrice__"]=1;
				if($this->priceDtArrayMap[$key][0]!=null && $this->priceDtArrayMap[$key][0]["__newPrice__"]==1){
					$this->priceDtArrayMap[$key][0] = $value[0];
				} else {
					array_unshift($this->priceDtArrayMap[$key], $value[0]);
				}
			}
			
			foreach($result["return"]["livePrice"] as $symbol=>$livePriceDtArray){
				$this->livePriceDtArrayMap[$symbol] = $livePriceDtArray;
			}
			foreach ($result["return"]["newLivePrice"] as $symbol=>$livePriceDtArray){
				while($this->livePriceDtArrayMap[$symbol][0] != null && $this->livePriceDtArrayMap[$symbol][0]["__newLivePrice__"] == 1){
					array_shift($this->livePriceDtArrayMap[$symbol]);
				}
				foreach($livePriceDtArray as $i => $livePriceDt){
					$livePriceDtArray[$i]["__newLivePrice__"]=1;
					array_unshift($this->livePriceDtArrayMap[$symbol], $livePriceDtArray[$i]);
				}
			}
			
			//alert(JSON::stringify($this->priceDtArrayMap[$stock_symbol]));
			//alert(JSON::stringify($this->livePriceDtArrayMap[$stock_symbol]));
			/*
			$this->chartViewMap["stock"]->priceDtArray = $this->priceDtArrayMap[$stock_symbol];
			$this->chartViewMap["vn"]->priceDtArray = $this->priceDtArrayMap["VNINDEX"];
			$this->chartViewMap["ha"]->priceDtArray = $this->priceDtArrayMap["HAINDEX"];
			$this->chartViewMap["stock"]->viewPaint();
			$this->chartViewMap["vn"]->viewPaint();
			$this->chartViewMap["ha"]->viewPaint();
			*/
			$this->chartViewMap["stock2"]->priceDtArray = $this->priceDtArrayMap[$stock_symbol];
			$this->chartViewMap["vn2"]->priceDtArray = $this->priceDtArrayMap["VNINDEX"];
			$this->chartViewMap["ha2"]->priceDtArray = $this->priceDtArrayMap["HAINDEX"];
			$this->chartViewMap["stock2"]->viewPaint();
			$this->chartViewMap["vn2"]->viewPaint();
			$this->chartViewMap["ha2"]->viewPaint();
			/*
			$this->chartViewMap["stock3"]->priceDtArray = $this->livePriceDtArrayMap[$stock_symbol];
			$this->chartViewMap["vn3"]->priceDtArray = $this->livePriceDtArrayMap["VNINDEX"];
			$this->chartViewMap["ha3"]->priceDtArray = $this->livePriceDtArrayMap["HAINDEX"];
			$this->chartViewMap["stock3"]->viewPaint();
			$this->chartViewMap["vn3"]->viewPaint();
			$this->chartViewMap["ha3"]->viewPaint();
			*/
			$livePriceView = new stock_price_LivePriceView();
			$livePriceDtMap = array(
				"VNINDEX" => $this->priceDtArrayMap["VNINDEX"][0],
				"HAINDEX" => $this->priceDtArrayMap["HAINDEX"][0],
				$stock_symbol => $this->priceDtArrayMap[$stock_symbol][0]
			);
			$html = $livePriceView->htmlLivePrice2($livePriceDtMap);
			$this->_("divLivePrice")->html($html);
		}
	}
	
	public function onClick($key, $event){
		if("buttonList" == $key){
			$symbol = strtoupper(trim($this->_("textStock")->prop("value")));
			$this->_("textStock")->prop("value", $symbol);
			if($symbol=="") $symbol = $this->_("selectStock")->prop("value");
			if($symbol!=""){
				$this->symbol = $symbol;
				$this->queryPriceDtArrayMap($symbol);
				$this->overviewHrefArray = array(
					"http://www.stockbiz.vn/Stocks/".$symbol."/Overview.aspx",
					"http://cafef.vn/hose/".$symbol."-chi-tiet-thong-tin-cong-ty-".$symbol."/0.chn"
				);
				$this->_("divButtonQuick")->children()->each( function($i, $element){
					if($symbol == _($element)->html()){
						_($element)->css("color", "red");
					}
				});
			}
		} else if("buttonNext" == $key){
			$selectedIndex = $this->_("selectStock")->prop("selectedIndex");
			$length = $this->_("selectStock")->prop("length");
			$selectedIndex++;
			if($selectedIndex==-1) $selectedIndex = $length-1;
			else if($selectedIndex==$length) $selectedIndex = 0;
			$this->_("selectStock")->prop("selectedIndex", $selectedIndex);
			$this->_("buttonList")->click();
		} else if("buttonBack" == $key){
			$selectedIndex = $this->_("selectStock")->prop("selectedIndex");
			$length = $this->_("selectStock")->prop("length");
			$selectedIndex--;
			if($selectedIndex==-1) $selectedIndex = $length-1;
			else if($selectedIndex==$length) $selectedIndex = 0;
			$this->_("selectStock")->prop("selectedIndex", $selectedIndex);
			$this->_("buttonList")->click();
		} else if("buttonSave" == $key){
			
		}
		else if("checkboxAuto" == $key){
			if($this->_("checkboxAuto")->prop("checked")==true){
				$this->tableView->filterType = $this->_("selectFilterType")->prop("value");
				$this->tableView->queryMap($this->tableView->filterType);
				//alert($this->_("selectFilterType")->prop("value"));
			}
		}
		else if("buttonVN" == $key){
			$divChartView = $this->_("divChartView");
			$divChartView->scrollTop($divChartView->scrollTop() + _($this->chartViewMap["vn"]->div)->position()->top);
		} else if("buttonHA" == $key){
			$divChartView = $this->_("divChartView");
			$divChartView->scrollTop($divChartView->scrollTop() + _($this->chartViewMap["ha"]->div)->position()->top);
		} else if("buttonStock" == $key){
			$divChartView = $this->_("divChartView");
			$divChartView->scrollTop($divChartView->scrollTop() + _($this->chartViewMap["stock"]->div)->position()->top);
		} else if("divButtonQuick" == $key){
			$target = _($event->target);
			if($target->attr("tag")=="buttonQuick"){
				$symbol = $target->html();
				if($symbol=="&nbsp;") $symbol="";
				$selectStock = $this->_("selectStock");
				$selectStock->children()->each(function($i, $element){
					if($element->value == $symbol) $selectStock->prop("selectedIndex", $i);
				});
				$this->_("buttonList")->click();
			}
		} else if("aOverview" == $key){
			$length = count($this->overviewHrefArray);
			for($i=0; $i<$length; $i++){
				if($i==1){
					$hrefArray = array(
						"S96" => "http://cafef.vn/hastc/S96-cong-ty-co-phan-song-da-906.chn"
						,"PVA" => "http://cafef.vn/hastc/PVA-cong-ty-co-phan-tong-cong-ty-xay-lap-dau-khi-nghe-an.chn"
						,"MCG" => "http://cafef.vn/hose/MCG-cong-ty-co-phan-co-dien-va-xay-dung-viet-nam.chn"
						,"CTG" => "http://cafef.vn/hose/CTG-ngan-hang-thuong-mai-co-phan-cong-thuong-viet-nam.chn"
						,"VCG" => "http://cafef.vn/hastc/VCG-tong-cong-ty-co-phan-xuat-nhap-khau-va-xay-dung-viet-nam.chn"
						,"PGS" => "http://cafef.vn/hastc/PGS-cong-ty-co-phan-kinh-doanh-khi-hoa-long-mien-nam.chn"
						,"WSS" => "http://cafef.vn/hastc/WSS-cong-ty-co-phan-chung-khoan-pho-wall.chn"
						,"DBC" => "http://cafef.vn/hastc/DBC-cong-ty-co-phan-dabaco-viet-nam.chn"
						,"HUT" => "http://cafef.vn/hastc/HUT-cong-ty-co-phan-tasco.chn"
						,"NTB" => "http://cafef.vn/hose/NTB-cong-ty-co-phan-dau-tu-xay-dung-va-khai-thac-cong-trinh-giao-thong-584.chn"
						,"PVC" => "http://cafef.vn/hastc/PVC-cong-ty-co-phan-dung-dich-khoan-va-hoa-pham-dau-khi.chn"
						,"OGC" => "http://cafef.vn/hose/OGC-cong-ty-co-phan-tap-doan-dai-duong.chn"
						,"CLG" => "http://cafef.vn/hose/CLG-cong-ty-co-phan-dau-tu-va-phat-trien-nha-dat-cotec.chn"
						,"THV" => "http://cafef.vn/hastc/THV-cong-ty-co-phan-tap-doan-thai-hoa-viet-nam.chn"
						,"KLS" => "http://cafef.vn/hastc/KLS-cong-ty-co-phan-chung-khoan-kim-long.chn"
						,"CSM" => "http://cafef.vn/hose/CSM-cong-ty-co-phan-cong-nghiep-cao-su-mien-nam.chn"
						,"NKG" => "http://cafef.vn/hose/NKG-cong-ty-co-phan-thep-nam-kim.chn"
						,"XMC" => "http://cafef.vn/hastc/XMC-cong-ty-co-phan-be-tong-va-xay-dung-vinaconex-xuan-mai.chn"
						,"SRC" => "http://cafef.vn/hose/SRC-cong-ty-co-phan-cao-su-sao-vang.chn"
						,"VNF" => "http://cafef.vn/hastc/VNF-cong-ty-co-phan-van-tai-ngoai-thuong.chn"
						,"XMC" => "http://cafef.vn/hastc/XMC-cong-ty-co-phan-be-tong-va-xay-dung-vinaconex-xuan-mai.chn"
						,"NAG" => "http://cafef.vn/hastc/NAG-cong-ty-co-phan-nagakawa-viet-nam.chn"
						,"HBS" => "http://cafef.vn/hastc/HBS-cong-ty-co-phan-chung-khoan-hoa-binh.chn"
						,"VIC" => "http://cafef.vn/hose/VIC-cong-ty-co-phan-vincom.chn"
						,"VNM" => "http://cafef.vn/hose/VNM-cong-ty-co-phan-sua-viet-nam.chn"
						,"KKC" => "http://cafef.vn/hastc/KKC-cong-ty-co-phan-san-xuat-va-kinh-doanh-kim-khi.chn"
						,"BVS" => "http://cafef.vn/hastc/BVS-cong-ty-co-phan-chung-khoan-bao-viet.chn"
						,"SSI" => "http://cafef.vn/hose/SSI-cong-ty-co-phan-chung-khoan-sai-gon.chn"
						,"SHN" => "http://cafef.vn/hastc/SHN-cong-ty-co-phan-dau-tu-tong-hop-ha-noi.chn"
						,"PVG" => "http://cafef.vn/hastc/PVG-cong-ty-co-phan-kinh-doanh-khi-hoa-long-mien-bac.chn"
						,"VE9" => "http://cafef.vn/hastc/VE9-cong-ty-co-phan-dau-tu-va-xay-dung-dien-vneco-9.chn"
						,"SCR" => "http://cafef.vn/hastc/SCR-cong-ty-co-phan-dia-oc-sai-gon-thuong-tin.chn"
						,"APS" => "http://cafef.vn/hastc/APS-cong-ty-co-phan-chung-khoan-chau-a-thai-binh-duong.chn"
						,"PHT" => "http://cafef.vn/hose/PHT-cong-ty-co-phan-san-xuat-va-thuong-mai-phuc-tien-.chn"
						,"SC5" => "http://cafef.vn/hose/SC5-cong-ty-co-phan-xay-dung-so-5.chn"
						,"HVG" => "http://cafef.vn/hose/HVG-cong-ty-co-phan-hung-vuong.chn"
						,"AGC" => "http://cafef.vn/hastc/AGC-cong-ty-co-phan-ca-phe-an-giang.chn"
						,"PVV" => "http://cafef.vn/hastc/PVV-cong-ty-co-phan-dau-tu-xay-dung-vinaconex-pvc.chn"
						,"VND" => "http://cafef.vn/hastc/VND-cong-ty-co-phan-chung-khoan-vndirect.chn"
						,"SDH" => "http://cafef.vn/hastc/SDH-cong-ty-co-phan-xay-dung-ha-tang-song-da.chn"
						,"CTS" => "http://cafef.vn/hastc/CTS-cong-ty-co-phan-chung-khoan-ngan-hang-cong-thuong-viet-nam.chn"
						,"PHH" => "http://cafef.vn/hastc/PHH-cong-ty-co-phan-hong-ha-dau-khi.chn"
						,"VSP" => "http://cafef.vn/hastc/VSP-ctcp-van-tai-bien-va-bat-dong-san-viet-hai.chn"
						,"STL" => "http://cafef.vn/hastc/STL-cong-ty-co-phan-song-da-thang-long.chn"
						,"STP" => "http://cafef.vn/hastc/STP-cong-ty-co-phan-cong-nghiep-thuong-mai-song-da.chn"
						,"TNG" => "http://cafef.vn/hastc/TNG-cong-ty-co-phan-dau-tu-va-thuong-mai-tng.chn"
						,"AVS" => "http://cafef.vn/hastc/AVS-cong-ty-co-phan-chung-khoan-au-viet.chn"
						,"LIG" => "http://cafef.vn/hastc/LIG-cong-ty-co-phan-licogi-13.chn"
						,"UNI" => "http://cafef.vn/hastc/UNI-cong-ty-co-phan-vien-lien.chn"
						,"HPC" => "http://cafef.vn/hastc/HPC-cong-ty-co-phan-chung-khoan-hai-phong.chn"
						,"SSM" => "http://cafef.vn/hastc/SSM-cong-ty-co-phan-che-tao-ket-cau-thep-vnecossm.chn"
						,"PSI" => "http://cafef.vn/hastc/PSI-cong-ty-co-phan-chung-khoan-dau-khi.chn"
						,"VGS" => "http://cafef.vn/hastc/VGS-cong-ty-co-phan-ong-thep-viet-duc-vg-pipe.chn"
						,"PVX" => "http://cafef.vn/hastc/PVX-tong-cong-ty-co-phan-xay-lap-dau-khi-viet-nam.chn"
						,"SD7" => "http://cafef.vn/hastc/SD7-cong-ty-co-phan-song-da-7.chn"
						,"API" => "http://cafef.vn/hastc/API-cong-ty-co-phan-dau-tu-chau-a-thai-binh-duong.chn"
						,"SD3" => "http://cafef.vn/hastc/SD3-cong-ty-co-phan-song-da-3.chn"
						,"DCS" => "http://cafef.vn/hastc/DCS-cong-ty-co-phan-tap-doan-dai-chau.chn"
						,"ORS" => "http://cafef.vn/hastc/ORS-cong-ty-co-phan-chung-khoan-phuong-dong.chn"
						,"KTB" => "http://cafef.vn/hose/KTB-cong-ty-co-phan-dau-tu-khoang-san-tay-bac.chn"
						,"KSS" => "http://cafef.vn/hose/KSS-tong-cong-ty-co-phan-khoang-san-na-ri-hamico.chn"
						,"PVL" => "http://cafef.vn/hastc/PVL-cong-ty-co-phan-bat-dong-san-dien-luc-dau-khi-viet-nam.chn"
						,"TDH" => "http://cafef.vn/hose/TDH-cong-ty-co-phan-phat-trien-nha-thu-duc.chn"
						,"KSA" => "http://cafef.vn/hose/KSA-cong-ty-co-phan-khoang-san-binh-thuan-hamico.chn"
						,"IDJ" => "http://cafef.vn/hastc/IDJ-cong-ty-co-phan-dau-tu-tai-chinh-quoc-te-va-phat-trien-doanh-nghiep-id.chn"
						,"HQC" => "http://cafef.vn/hose/HQC-cong-ty-co-phan-tu-van-thuong-mai-dich-vu-dia-oc-hoang-quan.chn"
						,"MCV" => "http://cafef.vn/hose/MCV-cong-ty-co-phan-cavico-viet-nam-khai-thac-mo-va-xay-dung.chn"
						,"PSG" => "http://cafef.vn/hastc/PSG-cong-ty-co-phan-dau-tu-va-xay-lap-dau-khi-sai-gon-.chn"
						,"SBA" => "http://cafef.vn/hose/SBA-cong-ty-co-phan-song-ba.chn"
						,"PPS" => "http://cafef.vn/hastc/PPS-cong-ty-co-phan-dich-vu-ky-thuat-dien-luc-dau-khi-vn.chn"
						,"ICF" => "http://cafef.vn/hose/ICF-cong-ty-co-phan-dau-tu-thuong-mai-thuy-san.chn"
						,"PVT" => "http://cafef.vn/hose/PVT-tong-cong-ty-co-phan-van-tai-dau-khi.chn"
						,"ANV" => "http://cafef.vn/hose/ANV-cong-ty-co-phan-nam-viet.chn"
						,"HDO" => "http://cafef.vn/hastc/HDO-cong-ty-co-phan-hung-dao-container.chn"
						,"CII" => "http://cafef.vn/hose/CII-cong-ty-co-phan-dau-tu-ha-tang-ky-thuat-tpho-chi-minh.chn"
						,"TLC" => "http://cafef.vn/hastc/TLC-cong-ty-co-phan-vien-thong-thang-long.chn"
						,"TDC" => "http://cafef.vn/hose/TDC-cong-ty-co-phan-kinh-doanh-va-phat-trien-binh-duong.chn"
						,"BVG" => "http://cafef.vn/hastc/BVG-cong-ty-co-phan-thep-bac-viet.chn"
						,"BTT" => "http://cafef.vn/hose/BTT-cong-ty-co-phan-thuong-mai-dich-vu-ben-thanh.chn"
						,"LGL" => "http://cafef.vn/hose/LGL-cong-ty-co-phan-dau-tu-va-phat-trien-do-thi-long-giang.chn"
						,"PNC" => "http://cafef.vn/hose/PNC-cong-ty-co-phan-van-hoa-phuong-nam.chn"
						,"MDG" => "http://cafef.vn/hose/MDG-cong-ty-co-phan-mien-dong.chn"
						,"DIG" => "http://cafef.vn/hose/DIG-tong-cong-ty-co-phan-dau-tu-phat-trien-xay-dung.chn"
						,"SBS" => "http://cafef.vn/hose/SBS-cong-ty-co-phan-chung-khoan-ngan-hang-sai-gon-thuong-tin.chn"
						,"WSS" => "http://cafef.vn/hastc/WSS-cong-ty-co-phan-chung-khoan-pho-wall.chn"
						,"FDC" => "http://cafef.vn/hose/FDC-cong-ty-co-phan-ngoai-thuong-va-phat-trien-dau-tu-thanh-pho-ho-chi-minh.chn"
						,"CTC" => "http://cafef.vn/hastc/CTC-cong-ty-co-phan-van-hoa-va-du-lich-gia-lai.chn"
						,"VOS" => "http://cafef.vn/hose/VOS-cong-ty-co-phan-van-tai-bien-viet-nam.chn"
						,"TSC" => "http://cafef.vn/hose/TSC-cong-ty-co-phan-vat-tu-ky-thuat-nong-nghiep-can-tho.chn"
						,"VFC" => "http://cafef.vn/hose/VFC-cong-ty-co-phan-vinafco.chn"
						,"NVC" => "http://cafef.vn/hastc/NVC-cong-ty-co-phan-nam-vang.chn"
						,"BBC" => "http://cafef.vn/hose/BBC-cong-ty-co-phan-bibica.chn"
						,"PPC" => "http://cafef.vn/hose/PPC-cong-ty-co-phan-nhiet-dien-pha-lai.chn"
						,"PTL" => "http://cafef.vn/hose/PTL-cong-ty-co-phan-dau-tu-ha-tang-va-do-thi-dau-khi.chn"
						,"BGM" => "http://cafef.vn/hose/BGM-cong-ty-co-phan-khai-thac-va-che-bien-khoang-san-bac-giang.chn"
						,"PVI" => "http://cafef.vn/hastc/PVI-cong-ty-co-phan-pvi.chn"
					);
					$href = $hrefArray[$this->symbol];
					if($href == null) $href = "http://cafef.vn";
					$__window->open($href,"__aOverview".$i);
				} else {
					$__window->open($this->overviewHrefArray[$i],"__aOverview".$i);
				}
			}
		} else if("buttonDetailHide" == $key){
			$this->_("divDetail")->css("visibility", "hidden");
		} else if("buttonDetailQueryInit" == $key){
			$this->queryInit();
		} else if("buttonDetailQueryInitCond" == $key){
			$this->queryInit($this->mapCond);
		} else if("tableView.div" == $key || "livePriceView.div" == $key || "divLivePrice" == $key){
			$target = _($event->target);
			if($target->prop("tag")=="aSymbol"){
				$symbol = $target->html();
				if($symbol=="&nbsp;") $symbol="";
				$selectStock = $this->_("selectStock");
				$selectStock->children()->each(function($i, $element){
					if($element->value == $symbol) $selectStock->prop("selectedIndex", $i);
				});
				$this->_("buttonList")->click();
				$this->onKeypress("document", array("target"=>$__document->body, "charCode"=>ord("Y")));
				if($symbol=="VNINDEX") $this->onKeypress("document", array("target"=>$__document->body, "charCode"=>ord("1")));
				else if($symbol=="HAINDEX") $this->onKeypress("document", array("target"=>$__document->body, "charCode"=>ord("2")));
				else $this->onKeypress("document", array("target"=>$__document->body, "charCode"=>ord("3")));
			}
		}
	}
	
	public function onDblclick($key, $event){
		if("divChartView" == $key){
			
		}
	}
	
	public $pageX;
	public $pageY;
	public function onMouseMove($key, $event){
		if("divChartView" == $key){
			if($event->pageX) $this->pageX = $event->pageX;
			if($event->pageY) $this->pageY = $event->pageY;
			if($this->enablePlus==true){
				$offset = $this->getOffset("divChartView");
				$this->_("divXPlus")->css("top", $offset->top);
				$this->_("divYPlus")->css("left", $offset->left);
			}
		}
	}
	public function getOffset($key){
		$this_ = $this->_($key);
		return array("top" => $this->pageY + $this_->scrollTop() - $this_->offset()->top, 
			"left" => $this->pageX + $this_->scrollLeft() - $this_->offset()->left
		);
	}

	public function onKeypress($key, $event){
		if("document" == $key){
			$target = _($event->target);
			$ch = strtoupper(chr($event->charCode));
			if($event->charCode==13){//enter
				$this->_("buttonList")->click();
			}
			if($event->target->tagName != "BODY") return;
			if($ch == "N"){
				$this->_("buttonNext")->click();
			} else if($ch == "B"){
				$this->_("buttonBack")->click();
			} else if($ch == "1"){
				$this->_("buttonVN")->click();
			} else if($ch == "2"){
				$this->_("buttonHA")->click();
			} else if($ch == "3"){
				$this->_("buttonStock")->click();
			} else if($ch == "T"){
				$divTableView = $this->_("divTableView");
				$divTableView->css("visibility", "visible");
				$this->toFront("divTableView");
			} else if($ch == "R"){
				$divLivePriceView = $this->_("divLivePriceView");
				$divLivePriceView->css("visibility", "visible");
				$this->toFront("divLivePriceView");
			} else if($ch == "Y"){
				$divTableView = $this->_("divTableView");
				$divTableView->css("visibility", "hidden");
				$divLivePriceView = $this->_("divLivePriceView");
				$divLivePriceView->css("visibility", "hidden");
			} else if($ch == "X"){
				if($this->enablePlus==false){
					$this->enablePlus = true;
					$this->_("divXPlus")->css("visibility", "visible");
					$this->_("divYPlus")->css("visibility", "visible");
					$this->_("divYPlus")->css("width", "1000px");
				} else{
					$this->enablePlus = false;
					$this->_("divXPlus")->css("visibility", "hidden");
					$this->_("divYPlus")->css("visibility", "hidden");
					$this->_("divYPlus")->css("width", "0px");
				}
				if($this->enablePlus==true){
					$this->onMouseMove("divChartView", $event);
				}
			} else if($ch == "F"){
				$this->chartViewMap["stock2"]->div->css("visibility", "visible");
				$this->chartViewMap["vn2"]->div->css("visibility", "visible");
				$this->chartViewMap["ha2"]->div->css("visibility", "visible");
				
				$this->chartViewMap["stock3"]->div->css("visibility", "visible");
				$this->chartViewMap["vn3"]->div->css("visibility", "visible");
				$this->chartViewMap["ha3"]->div->css("visibility", "visible");
			} else if($ch == "G"){
				$this->chartViewMap["stock2"]->div->css("visibility", "visible");
				$this->chartViewMap["vn2"]->div->css("visibility", "visible");
				$this->chartViewMap["ha2"]->div->css("visibility", "visible");
				
				$this->chartViewMap["stock3"]->div->css("visibility", "hidden");
				$this->chartViewMap["vn3"]->div->css("visibility", "hidden");
				$this->chartViewMap["ha3"]->div->css("visibility", "hidden");
			} else if($ch == "H"){
				$this->chartViewMap["stock2"]->div->css("visibility", "hidden");
				$this->chartViewMap["vn2"]->div->css("visibility", "hidden");
				$this->chartViewMap["ha2"]->div->css("visibility", "hidden");
				
				$this->chartViewMap["stock3"]->div->css("visibility", "hidden");
				$this->chartViewMap["vn3"]->div->css("visibility", "hidden");
				$this->chartViewMap["ha3"]->div->css("visibility", "hidden");
			} else if($ch == "V"){
				$offset = $this->getOffset("divChartView");
				$i = $this->chartViewMap["stock"]->getI($offset->left);
				if($i<0) $i=0;
				$divDetail = $this->_("divDetail");
				$divDetail->css(array("visibility"=>"visible", 
					"left"=>$offset->left - $divDetail->width() - 1, 
					"top"=>$offset->top - $divDetail->height() - 1
				));
				$divDetailText = $this->_("divDetailText");
				$priceDt = $this->chartViewMap["stock"]->priceDtArray[$i];
				$priceDt1 = $this->chartViewMap["stock"]->priceDtArray[$i+1];
				$priceDt2 = $this->chartViewMap["stock"]->priceDtArray[$i+2];
				$divDetailText->html("");
				if($priceDt == null || $priceDt1 == null || $priceDt2 == null) return;
				$this->mapCond["maCode"] = $priceDt["maCode"];
				$this->mapCond["maCode1"] = $priceDt1["maCode"];
				$this->mapCond["maCode2"] = $priceDt2["maCode"];
?>
<$html>
	symbol : <?= $priceDt["stock_symbol"] ?> [ <?= $i ?> ]<br/>
	maPercent1 : <?= round($priceDt["maPercent1"]) ?><br/>
	maPercent2 : <?= round($priceDt["maPercent2"]) ?><br/>
	maPercent3 : <?= round($priceDt["maPercent3"]) ?><br/>
	maPercent4 : <?= round($priceDt["maPercent4"]) ?><br/>
	maCode : <?= $this->mapCond["maCode"] ?><br/>
	maCode1 : <?= $this->mapCond["maCode1"] ?><br/>
	maCode2 : <?= $this->mapCond["maCode2"] ?><br/>
</$html>
<?
				$divDetailText->html($html);
			}
		}
	}
	
	public $mapCond = array("__new__"=>1);
	public $queryInitFile = "WEB-INF/files/stock/analyser/queryInit.json";
	public function queryInit($mapCond){
		//<@ $this->jsonp($mapCond);
		$return = array("__new__"=>1);
		$priceDtArrayMap = $this->getPriceDtArrayMap($mapCond);
		$return["arrayStock_symbol"] = array_keys($priceDtArrayMap);
		$this->saveJson($this->queryInitFile, $return);
		return $return;
		//@>
	}
	
	public $priceDtArrayMapFile = "WEB-INF/files/stock/analyser/priceDtArrayMap.json";
	public function deletePriceDtArrayMap(){
		if(file_exists($this->priceDtArrayMapFile)) unlink($this->priceDtArrayMapFile);
	}
	public function getPriceDtArrayMap($mapCond){
		//<@
		function sortFunc($a, $b){				
			if($a[0]["rate"] < $b[0]["rate"]) return -1;
			if($a[0]["rate"] > $b[0]["rate"]) return 1;
			return 0;
		}
		function sortFunc1($a, $b){				
			if($a[0]["megaCount"] > $b[0]["megaCount"]) return -1;
			if($a[0]["megaCount"] < $b[0]["megaCount"]) return 1;
			return 0;
		}
		function sortFunc2($a, $b){				
			if($a[0]["value2"] > $b[0]["value2"]) return -1;
			if($a[0]["value2"] < $b[0]["value2"]) return 1;
			return 0;
		}
		$priceDtArrayMap = $this->loadJson($this->priceDtArrayMapFile);
		if($priceDtArrayMap==null){
			$sql = "SELECT * 
				FROM stock_price_PriceVo 
				WHERE stockDate>=DATE_SUB(NOW(), INTERVAL 100 DAY)
				ORDER BY stockDate DESC";
			$stm = $this->ds->prepare($sql);
			$stm->execute();
			$priceDtArray = $stm->fetchAll(PDO::FETCH_ASSOC);
			foreach($priceDtArray as $i=>$priceDt){
				$symbol = $priceDt["stock_symbol"];
				if($priceDtArrayMap[$symbol]==null) $priceDtArrayMap[$symbol]=array();
				array_push($priceDtArrayMap[$symbol],$priceDt);
			}
			$this->saveJson($this->priceDtArrayMapFile, $priceDtArrayMap);
		}
		/*
		$sql = "SELECT * 
			FROM stock_price_LivePriceVo 
			WHERE stockDate=(SELECT MAX(lp.stockDate) FROM stock_price_LivePriceVo lp)
			ORDER BY stockDate DESC";
		$stm = $this->ds->prepare($sql);
		$stm->execute();
		$livePriceDtArray = $stm->fetchAll(PDO::FETCH_ASSOC);
		foreach($livePriceDtArray as $i=>$livePriceDt){
			$symbol = $livePriceDt["stock_symbol"];
			$livePriceDt["__newPrice__"]=1;
			if($priceDtArrayMap[$symbol]==null) $priceDtArrayMap[$symbol]=array();
			if($priceDtArrayMap[$symbol][0]["__newPrice__"]==1){
				$this->priceDtArrayMap[$symbol][0] = $livePriceDt;
			} else {
				array_unshift($priceDtArrayMap[$symbol], $livePriceDt);
			}
		}
		*/
		$livePriceView = new stock_price_LivePriceView();
		$livePriceDtMap = $livePriceView->queryMapAll();
		foreach($livePriceDtMap as $symbol=>$livePriceDt){
			$symbol = $livePriceDt["stock_symbol"];
			$livePriceDt["__newPrice__"]=1;
			if($priceDtArrayMap[$symbol]==null) $priceDtArrayMap[$symbol]=array();
			if($priceDtArrayMap[$symbol][0]["__newPrice__"]==1){
				$this->priceDtArrayMap[$symbol][0] = $livePriceDt;
			} else {
				array_unshift($priceDtArrayMap[$symbol], $livePriceDt);
			}
		}
		
		foreach($priceDtArrayMap as $symbol => &$priceDtArray){
			$chartView = new stock_analyser_ChartView();
			$chartView->priceDtArray = &$priceDtArray;
			$chartView->makeFirst();
		}
		foreach($priceDtArrayMap as $symbol=>&$priceDtArray){
			if($priceDtArray[0]["value2"]<1000000) unset($priceDtArrayMap[$symbol]);
		}
		unset($priceDtArrayMap["VNINDEX"]);
		unset($priceDtArrayMap["HAINDEX"]);
		unset($priceDtArrayMap["VNindex"]);
		
		uasort($priceDtArrayMap,"sortFunc2");
		$arrayRate = array(
			"ITA" => -1000,
			"PGC" => -1000
		);
		$i=0;
		foreach($priceDtArrayMap as $symbol=>$priceDtArray){
			$i++;
			$priceDtArrayMap[$symbol][0]["rate"] = $i;
			//if($i>=60) unset($priceDtArrayMap[$symbol]);
		}
		foreach($arrayRate as $symbol=>$rate){
			$priceDtArrayMap[$symbol][0]["rate"] += $rate;
		}
		uasort($priceDtArrayMap,"sortFunc");
		
		if($mapCond != null){
			$maCode = $mapCond["maCode"];
			$maCode1 = $mapCond["maCode1"];
			$maCode2 = $mapCond["maCode2"];
			if($maCode != null && $maCode1 != null && $maCode2 != null){
				foreach($priceDtArrayMap as $symbol=>&$priceDtArray){
					$chartView = new stock_analyser_ChartView();
					$chartView->priceDtArray = &$priceDtArray;
					$chartView->makeMa(3);
					//print_p($priceDtArray[1]);
					if($priceDtArray[0]["maCode"] != $maCode) unset($priceDtArrayMap[$symbol]);
					if($priceDtArray[1]["maCode"] != $maCode1) unset($priceDtArrayMap[$symbol]);
					if($priceDtArray[2]["maCode"] != $maCode2) unset($priceDtArrayMap[$symbol]);
				}
			}
			//print_p($maCode);
		}
		return $priceDtArrayMap;
		//@>
	}

	protected $stmPriceDtArray;
	public function queryPriceDtArray($stock_symbol){
		//<@ $this->jsonp($stock_symbol);
		if($this->stmPriceDtArray == null){
			$vo = new stock_price_PriceVo();
			$sql = "SELECT ";
			foreach ($vo as $key=>$value){
				$sql .= "$key,";
			}
			$sql = substr($sql, 0, -1) . " ";
			
			$sql .= "FROM ".get_class($vo)." 
				WHERE stock_symbol =:stock_symbol AND stockDate>=DATE_SUB(NOW(), INTERVAL 200 DAY)
				ORDER BY stockDate DESC
			";
			/*
			$sql .= "FROM ".get_class($vo)." 
				WHERE stock_symbol =:stock_symbol AND stockDate<='2008-01-01' AND stockDate>=DATE_SUB('2008-01-01', INTERVAL 200 DAY)
				ORDER BY stockDate DESC
			";
			*/
			$this->stmPriceDtArray = $this->ds->prepare($sql);
		}
		$this->stmPriceDtArray->execute(array("stock_symbol"=>$stock_symbol));
		$return = $this->stmPriceDtArray->fetchAll(PDO::FETCH_OBJ);
		for($i=0; $i<count($return); $i++) {
			$return[$i]->open = (double)$return[$i]->open;
			$return[$i]->high = (double)$return[$i]->high;
			$return[$i]->low = (double)$return[$i]->low;
			$return[$i]->close = (double)$return[$i]->close;
			$return[$i]->volume = (int)$return[$i]->volume;
		}
		return $return;
		//@>
	}
	
	protected $stmLivePriceDtArray;
	public function queryLivePriceDtArray($stock_symbol){
		//<@ $this->jsonp($stock_symbol);
		return array();
		if($this->stmLivePriceDtArray == null){
			$vo = new stock_price_LivePriceVo();
			$sql = "SELECT ";
			foreach ($vo as $key=>$value){
				$sql .= "$key,";
			}
			$sql = substr($sql, 0, -1) . " ";
			$sql .= "FROM ".get_class($vo)." 
				WHERE stock_symbol =:stock_symbol AND stockDate>=DATE_SUB(NOW(), INTERVAL 30 DAY) AND stockDate<=DATE(NOW())
				ORDER BY stockDate DESC
			";
			$this->stmLivePriceDtArray = $this->ds->prepare($sql);
		}
		$this->stmLivePriceDtArray->execute(array("stock_symbol"=>$stock_symbol));
		$return = $this->stmLivePriceDtArray->fetchAll(PDO::FETCH_OBJ);
		for($i=count($return) - 1; $i>=0; $i--) {
			$return[$i]->open = (double)$return[$i]->open;
			$return[$i]->high = (double)$return[$i]->high;
			$return[$i]->low = (double)$return[$i]->low;
			$return[$i]->close = (double)$return[$i]->close;
			$return[$i]->volume = (int)$return[$i]->volume;
			
			//if($i-1 >= 0 && substr($return[$i]->stockDate, 0, 10) == substr($return[$i-1]->stockDate, 0, 10)) $return[$i]->volume = ($return[$i]->volume - $return[$i-1]->volume);
		}
		return $return;
		//@>
	}
	
	public function queryPriceDtArrayMap($stock_symbol, $includePrice, $includePriceIndex){
		/*<@ 
		if($this->priceDtArrayMap[$stock_symbol] == null){
			$includePrice = true;
			if($this->priceDtArrayMap["VNINDEX"] == null) $includePriceIndex=true;
			else $includePriceIndex=false;
		} else {
			$includePrice = false;
			$includePriceIndex = null;
			$return = array("__new__",1);
			$return[$stock_symbol] = $this->priceDtArrayMap[$stock_symbol];
			$return["VNINDEX"] = $this->priceDtArrayMap["VNINDEX"];
			$return["HAINDEX"] = $this->priceDtArrayMap["HAINDEX"];
		}
		@>*/
		//<@ $this->jsonp($stock_symbol, $includePrice, $includePriceIndex);
		$return = array("__new__"=>1, "price"=>array("__new__"=>1), "newPrice"=>array("__new__"=>1), "livePrice"=>array("__new__"=>1), "newLivePrice"=>array("__new__"=>1));
		if($includePrice == true){
			$return["price"][$stock_symbol] = $this->queryPriceDtArray($stock_symbol);
			if($includePriceIndex == true){
				$return["price"]["VNINDEX"] = $this->queryPriceDtArray("VNINDEX");
				$return["price"]["HAINDEX"] = $this->queryPriceDtArray("HAINDEX");
			}
			
			$return["livePrice"][$stock_symbol] = $this->queryLivePriceDtArray($stock_symbol);
			if($includePriceIndex == true){
				$return["livePrice"]["VNINDEX"] = $this->queryLivePriceDtArray("VNINDEX");
				$return["livePrice"]["HAINDEX"] = $this->queryLivePriceDtArray("HAINDEX");
			}
		}
		$livePriceView = new stock_price_LivePriceView();
		$livePriceDtMap = $livePriceView->queryMapAll();
		$return["newPrice"][$stock_symbol] = array($livePriceDtMap[$stock_symbol]);
		$return["newPrice"]["VNINDEX"] = array($livePriceDtMap["VNINDEX"]);
		$return["newPrice"]["HAINDEX"] = array($livePriceDtMap["HAINDEX"]);
		
		$return["newLivePrice"][$stock_symbol] = array();
		$return["newLivePrice"]["VNINDEX"] = array();
		$return["newLivePrice"]["HAINDEX"] = array();
		
		$livePriceDtMapMap = $livePriceView->queryMapMapAll();
		foreach($livePriceDtMapMap as $date => $livePriceDtMap){
			array_push($return["newLivePrice"][$stock_symbol], $livePriceDtMap[$stock_symbol]);
			array_push($return["newLivePrice"]["VNINDEX"], $livePriceDtMap["VNINDEX"]);
			array_push($return["newLivePrice"]["HAINDEX"], $livePriceDtMap["HAINDEX"]);
		}
		
		return $return;
		//@>
	}
}
